package day9.homework;

import java.util.concurrent.locks.ReentrantLock;

//a.实现一个多线程统计出1-100之间  2、3、5的倍数有哪些?
//   线程1先展示一共2的倍数有哪些
//   线程2再展示一共3的倍数有哪些
//   线程3最后展示一共5的倍数有哪些
public
class Demo1 {
    public static
    void main(String[] args) {
        new Thread( new lh(1,2),"线程一").start();
        new Thread( new lh(2,3),"线程二").start();
        new Thread( new lh(3,5),"线程三").start();
    }
}
class lh implements Runnable{
    int index;
    int id;
    static int current=1;
    public lh(int id,int index){
        this.id=id;
        this.index=index;
    }
    @Override
    public
    void run() {
        String name = Thread.currentThread().getName();
        synchronized (Demo1.class) {
            while (current != id) {
                try {
                    Demo1.class.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println(name + index + "的倍数：");
            for (int i = 1; i < 101; i++) {
                if (i % index == 0) {
                    System.out.print(i + " ");
                }
            }
            current++;
            System.out.println();
            Demo1.class.notifyAll();
        }
    }
    }
